package com.beagle.njddapp.ui.fragment;

import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beagle.njddapp.R;
import com.beagle.njddapp.base.BaseMvpFragment;
import com.beagle.njddapp.bean.owner.OilOrderBean;
import com.beagle.njddapp.ui.activity.owner.NjOilOrderDetailActivity;
import com.beagle.njddapp.ui.adapter.OilOrderAdapter;
import com.beagle.njddapp.ui.adapter.inter.RecyclerViewItemClickLisenter;
import com.beagle.njddapp.ui.presenter.OilOrderPresenter;
import com.beagle.njddapp.ui.view.OilOrderView;
import com.blankj.utilcode.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author hxx
 * @date 2021-03-15 19:29
 * 农机主-加油订单
 */
public class OilOrderFragment extends BaseMvpFragment<OilOrderView, OilOrderPresenter> implements OilOrderView, RecyclerViewItemClickLisenter<OilOrderBean> {

    @BindView(R.id.common_recyclerview)
    RecyclerView recyclerView;
    @BindView(R.id.ll_empty)
    View empty;
    private OilOrderAdapter adapter;
    private List<OilOrderBean> oilOrderBeanList;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_recyclerview;
    }

    @Override
    public void init() {
        oilOrderBeanList = new ArrayList<>();
        presenter.fuelOrders(1000, 1);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new OilOrderAdapter(oilOrderBeanList, getActivity());
        adapter.setOilHomeBeanRecyclerViewItemClickLisenter(this);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public OilOrderView getMvpView() {
        return this;
    }

    @Override
    public OilOrderPresenter createPresenter() {
        return new OilOrderPresenter();
    }

    @Override
    public void onError(String message) {
        ToastUtils.showShort(message);
    }


    @Override
    public void showOrders(List<OilOrderBean> results) {
        if (results==null||results.size()<1){
            empty.setVisibility(View.VISIBLE);
            return;
        }
        empty.setVisibility(View.GONE);
        oilOrderBeanList.addAll(results);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onItemClickLisenter(OilOrderBean oilOrderBean) {
        startActivity(new Intent(getContext(), NjOilOrderDetailActivity.class).putExtra("orderId",oilOrderBean.getOrderId()));
    }
}
